package com.whz.enummap.plant;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import static java.util.stream.Collectors.groupingBy;

/**
 * @Author: sinosoft
 * @Description: 使用Stream表达式管理映射要更加简短
 * 但是Map的底层不会是EnumMap
 * @Date: Create in 10:20 2021/5/17
 * @Modified By:
 */
public class PlantMainTest_Stream {
    public static void main(String[] args) {
        Plant[] garden = new Plant[] {
                new Plant("白菊花", Plant.LifeCycle.ANNUAL),
                new Plant("黄菊花", Plant.LifeCycle.ANNUAL),
                new Plant("橄榄菊", Plant.LifeCycle.BIENNIAL),
                new Plant("银冠花", Plant.LifeCycle.PERENNIAL)
        };
        Map<Plant.LifeCycle, List<Plant>> plantMap =
                Arrays.stream(garden).collect(groupingBy(p -> p.lifeCycle));
        System.out.println(plantMap.getClass());
    }
}
